/*
* 文件：Console.cs
* 作者：王阳
* 时间：2019-5-20
* 描述：Unity控制台系统
*/

using System;

namespace UnityX
{
    /// <summary>
    /// Unity控制台系统
    /// </summary>
    public static class Console
    {
        private static ConsoleUI consoleUI;

        /// <summary>
        /// 是否显示控制台界面
        /// </summary>
        public static bool isShow
        {
            get
            {
                return consoleUI.isOpen;
            }
            set
            {
                if (value)
                {
                    consoleUI.Open();
                }
                else
                {
                    consoleUI.Close();
                }
            }
        }
        /// <summary>
        /// 初始化控制台
        /// </summary>
        internal static void Init()
        {
            if (consoleUI != null)
            {
                return;
            }
            consoleUI = new ConsoleUI(512);
            consoleUI.OnInput = UIInputHandler;
        }
        private static void UIInputHandler(string text)
        {
            DateTime dateTime = DateTime.Now;
            consoleUI.Add("输入指令：" + text, dateTime, "Console.InputCommand()", UnityEngine.LogType.Assert);
            if (!CSharpX.Command.Execute(text))
            {
                consoleUI.Add("输入指令无效，指令列表（不区分大小写）：" + CSharpX.Command.GetAllCommandInfo(), dateTime, "Console.ExecuteCommand()", UnityEngine.LogType.Assert);
            }
        }
        /// <summary>
        /// 写消息到控制台窗口
        /// </summary>
        /// <param name="content"></param>
        /// <param name="time"></param>
        /// <param name="stack"></param>
        /// <param name="type"></param>
        public static void Write(string content, DateTime time, string stack, UnityEngine.LogType type)
        {
            consoleUI.Add(content, time, stack, type);
        }
        /// <summary>
        /// 清空控制台消息
        /// </summary>
        public static void Clear()
        {
            consoleUI.Clear();
        }
        /// <summary>
        /// 设置字体
        /// </summary>
        /// <param name="font"></param>
        public static void SetFont(UnityEngine.Font font)
        {
            consoleUI.SetFont(font);
        }
    }
}